<template>
  <div class="app-container">

    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="customForm" :model="customForm" label-width="110px">
        <el-row>
          <el-col :span='12'>
            <el-form-item label="电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入电话" />
            </el-form-item>
          </el-col>
          <el-col :span='12'>
            <el-form-item label="" prop="phoneStatus">
              <el-radio-group v-model="phoneStatus" @input='selectPhoneStatus'>
                <el-radio-button label="无人接听"></el-radio-button>
                <el-radio-button label="直接挂断"></el-radio-button>
                <el-radio-button label="不需要"></el-radio-button>
                <el-radio-button label="关机"></el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span='12'>
            <el-form-item label="渠道" prop="channel">
              <el-input v-model="form.channel" placeholder="请输入渠道" />
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
            <el-form-item label="别名" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请输入别名" />
            </el-form-item>
          </el-col>
          <el-col :span='12' >
            <el-form-item label="" prop="remark">
              <el-input v-model="customForm.record" type="textarea" rows='5' placeholder="跟进备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span='12'>
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="form.sex">
                <el-radio-button label="男"></el-radio-button>
                <el-radio-button label="女"></el-radio-button>
              </el-radio-group>
            </el-form-item>
              <el-form-item label="星级" prop="level">
                <el-rate v-model="form.level"></el-rate>
              </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" filterable placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.custom_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="分组" prop="groupType">
              <el-select v-model="form.groupType" filterable  placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.custom_group_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="其他资质" prop="otherCert">
              <el-input v-model="form.otherCert" type="textarea" rows='5' placeholder="请输入其他资质" />
            </el-form-item>
            <el-form-item label="附属信息" prop="sateInfo">
              <el-checkbox-group v-model="form.sateInfo" >
                <el-checkbox v-for="city in sateInfos" :label="city" :key="city">{{city}}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span='10'>
            <el-timeline style='margin-left: 80px;'>
              <el-timeline-item
                v-for="(record, index) in recordList"
                :key="index"
                icon="el-icon-more"
                type="primary"
                color="#0bbd87"
                size="large"
                placement='top'
                :timestamp="record.createBy + record.createTime">
                {{record.record}}
              </el-timeline-item>
            </el-timeline>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提交并关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getCustom } from "@/api/custom/custom";
import { addRecord, listRecord } from '@/api/custom/record'

const cityOptions = ['本地人', '车', '房', '信用卡','寿险保单','公积金','社保','打发工资','营业执照'];
export default {
  name: "CustomDetail",
  dicts: ['custom_status','custom_group_type'],
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      customForm:{},
      checkedInfos: [],
      sateInfos:cityOptions,
      phoneStatus:"",
      recordList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customId: null,
      },
      // 总条数
      total: 0,
    };
  },
  created() {
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        no: null,
        name: null,
        phone: null,
        rename: null,
        sex: null,
        channel: null,
        level: null,
        status: "0",
        groupType: null,
        otherCert: null,
        sateInfo: null,
        remark: null,
        createBy: null,
        createTime: null,
      };
    },
    recordReset(){
      this.phoneStatus = null,
      this.customForm = {
        record:null
      }
    },
    /** 修改按钮操作 */
    handleDetail(id) {
      this.reset();
      this.recordReset();
      this.getRecordList(id);
      getCustom(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.form.sateInfo = JSON.parse(response.data.sateInfo);
        this.title = "跟进客户";
      });
    },
    selectPhoneStatus(value){
      this.customForm.record = value;
    },
    getRecordList(id) {
      console.log("*****");
      this.queryParams.customId = id;
      this.queryParams.type = 1;
      console.log(this.queryParams);
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["customForm"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.customForm.customId = this.form.id;
            addRecord(this.customForm).then(response => {
              this.$modal.msgSuccess("跟进成功");
              this.open = false;
              this.$emit('refresh')
            });
          }
        }
      });
    },
  }
};
</script>
